package cn.itcast.hotel.mq;

import cn.itcast.hotel.constatnts.MqConstants;
import cn.itcast.hotel.service.IHotelService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HotelListener {
    @Autowired
    private IHotelService hotelService;
    @RabbitListener(bindings=@QueueBinding(
            value= @Queue(MqConstants.HOTEL_INSERT_QUEUE),
            exchange = @Exchange(value=MqConstants.HOTEL_EXCHANGE,type = ExchangeTypes.DIRECT),
            key = MqConstants.HOTEL_INSERT_KEY
    ))
    public void saveOrUpdateEs(String jsonString){
        hotelService.saveOrUpdateEs(jsonString);
    }
    @RabbitListener(bindings=@QueueBinding(
            value= @Queue(MqConstants.HOTEL_DELETE_QUEUE),
            exchange = @Exchange(value=MqConstants.HOTEL_EXCHANGE,type = ExchangeTypes.DIRECT),
            key = MqConstants.HOTEL_DELETE_KEY
    ))
    public void deleteEs(String id){
        hotelService.deleteEs(id);
    }
}
